<!DOCTYPE html>
<html>

<body>
    <p>1</p>
    <p>创建一个对象</p>
    <p id="para"></p>
    <script>
        var user = {
            firstname: "Json",
            lastname: "nhooo",
            age: 22,
            location: "New Delhi"
        };

        document.getElementById("para").innerHTML = user.firstname + "lives in" + user.location;
    </script>

    <br>
    <br>
    <p>2</p>
    <p>有两种访问对象属性的方法：</p>
    <p>您可以使用object.property或object [" property"]：</p>
    <p id="JsHf"></p>
    <p id="JsHn"></p>

    <script>
        var user = {
            firstname: "www",
            lastname: "(cainiao.jc.com)",
            age: 22,
            location: "New Delhi"
        };
        document.getElementById("JsHf").innerHTML = user.firstname + " " + user.lastname;
        document.getElementById("JsHn").innerHTML = user["age"] + " " + user["location"];
    </script>

    <br>
    <br>
    <p>3 this的用法</p>
    <p>对象方法是函数定义，存储为属性值：</p>
    <p>您以<b> objectName.methodName()</b>：</p>的形式访问对象方法
    <p id="JsMm"></p>
    <script>
        var user = {
            firstName: "www.",
            lastName: "(cainiaojc.com)",
            age: 22,
            location: "New Delhi",
            getName: function() {
                return this.firstName + " " + this.lastName;
            }
        };
        document.getElementById("JsMm").innerHTML = user.getName();
    </script>

    <br>
    <br>
    <p>4</p>
    <p>如果访问without ()的对象方法，它将返回函数定义：</p>
    <p id="gggg"></p>
    <script>
        var user = {
            firstName: "www",
            lastName: "(cainiaojc.com)",
            age: 22,
            location: "New Delhi",
            getPame: function() {
                return this.firstName + " " + this.lastName;
            }
        };

        document.getElementById("gggg").innerHTML = user.getPame;
    </script>
</body>

</html>